//
//  CustomChatTableViewCell.m
//  IOSTest
//
//  Created by Afluy on 14/12/30.
//  Copyright (c) 2014年 Afluy. All rights reserved.
//

#import "CustomChatTableViewCell.h"
@interface CustomChatTableViewCell(){
    UIImageView *mLeftImg;
    UIImageView *mRightImg;
    UITextField *mLeftContent;
    UITextField *mRightContent;
}
@end

@implementation CustomChatTableViewCell

- (void)awakeFromNib {
    
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    return  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
}

-(UIView *) getCellView:(UIImage *)image text:(NSString*) content from:(BOOL)fromSelf {
    //头像
    UIImageView *iconImg =[[UIImageView alloc] initWithImage:image];
    iconImg.frame= CGRectMake(fromSelf ? (320-60):10, 0, 50, 50);
    
    
    UIFont *font=[UIFont systemFontOfSize:14];
    CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(80.0f, 2000.0f) lineBreakMode:NSLineBreakByWordWrapping] ;
    NSLog(@"%f,%f",size.width,size.height);
    //添加文本信息
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(fromSelf ? (320-80-size.width):80.f, 10.f, size.width, size.height)];
    [label setBackgroundColor:[UIColor clearColor]];
    label.font=font;
    label.numberOfLines= 0;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.text= content;
    
    //对话背景图片
    UIImage *bubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:fromSelf ? @"bubble_right":@"bubble_left" ofType:@"png"]];
    UIImageView *labelBgView = [[UIImageView alloc]initWithImage:[bubble stretchableImageWithLeftCapWidth:floorf(bubble.size.width/2) topCapHeight:floorf(bubble.size.height/2)]];
    
    labelBgView.frame = CGRectMake(fromSelf ? (320-90-size.width):70.f,0, label.frame.size.width+10.f, label.frame.size.height+10.f);
    
    
    
    return nil;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    }

@end
